<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <span>岳麓书院知识管理系统后台</span>
      </div>
      <el-dropdown @command="handleCommand">
        <el-button class="dropdown-button">
          更多操作<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown" class="dropdown-menu">
          <el-dropdown-item command="1" class="dropdown-item">返回首页</el-dropdown-item>
          <el-dropdown-item command="2" class="dropdown-item">退出登陆</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <div  id="menu" style="height: 1000px">
          <el-menu 
            :default-active="this.$router.path"
            class="el-menu-vertical"
            
            background-color="#770000"
            text-color="#fff"
            :router="true"
          >
          <div class="userinfo">
        <span>欢迎回来</span>
      </div>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-setting"></i>
              <span slot="title">个人主页</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/edinfo">
                <i class="el-icon-menu"></i>
                <span slot="title">个人信息</span>
              </el-menu-item>
              <el-menu-item index="/edhome/changepassword">
                <i class="el-icon-edit"></i>
                <span slot="title">修改密码</span>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-menu-item index="/edhome/acstar">
            <template slot="title">
              <i class="el-icon-magic-stick"></i>
              <span slot="title">书院收藏</span>
            </template>
          </el-menu-item>

          <el-submenu index="4">
          <template slot="title">
            <i class="el-icon-chat-line-round"></i>
            <span slot="title">论坛管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/edhome/blognews">
              <i class="el-icon-message"></i>
              <span slot="title">消息提示</span>
            </el-menu-item>
            <el-menu-item index="/edhome/blogpub">
              <i class="el-icon-position"></i>
              <span slot="title">我的发布</span>
            </el-menu-item>
            <el-menu-item index="/edhome/blogstar">
              <i class="el-icon-star-off"></i>
              <span slot="title">我的收藏</span>
            </el-menu-item>
            <el-menu-item index="/edhome/bloghistory">
              <i class="el-icon-s-order"></i>
              <span slot="title">我的足迹</span>
            </el-menu-item>
          </el-menu-item-group>
        </el-submenu>

        <el-menu-item index="/edhome/perjournal">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span slot="title">个人日志</span>
            </template>
          </el-menu-item>
        
        </el-menu>
        </div>
      </el-aside>
      <!-- 右侧内容主题 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import requests from '@/api/ajax';
import { mapState } from 'vuex';
import store from '@/store';
export default {
  data() {
    return{
      openeds: ['1','2'],
      uniqueOpened: false,
      userName: '',
    }
  },

  methods: {
    
    // // 将路由值保存到本地,同时再created里面申明
    // activePath(path) {
    //   window.sessionStorage.setItem('activePath', path)
    //   this.activePath = path
    // },
    handleOpen(key, keyPath) {
        // console.log(key, keyPath);
    },
    handleCommand(command) {
    if(command == 2){
      window.localStorage.clear()
      this.$router.push('/login')
    }else if (command == 1) {
      this.$router.push('/home')
    }
  }
  },
  mounted() {
		// requests.get('/users/userMassage').then((res) => {
		// 	this.userName = res.data.userName
		// 	console.log(res.data.userName)
		// })
    
  //   let that = this;
  //   window.addEventListener("serItemEvent", function(e) {
  //     if (e.key == username) {
  //       that.userName = e.username
  //     }
  //   })

  this.userName = window.localStorage.getItem('username')
  console.log(window.localStorage.username);
  
	}
  
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  padding-left: 5px;
  background-color: #770000;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
    span {
      margin-left: 15px;
    }
    
  }
}
.dropdown-button {
  background-color: #6e3b3b;
  color: #fff;
  border: #b2b5bd;
}
.dropdown-button:hover {
  color: #000000;
  background-color: #7e6060;
  border: #b2b5bd;
}
.dropdown-button:focus {
  color: #000000;
  background-color: #7e6060;
  border: #b2b5bd;
}
.el-aside{
  background-color: #770000;
}
  .el-menu {
    background-color: #ffffff;
    border-right: none;
  }
  .el-menu-item {
    background-color: #ffffff;
  }

.el-main {
  background-color: #eaedf1;
}
.iconfont {
  padding-right: 10px;
}
.el-main {
  background-color: rgb(241, 241, 241);
}
.userinfo {
  height: 50px;
  width: 100%;
  background-color: #6e3b3b;
  color: #fff;
  text-align: center;
  line-height: 50px;
}
.el-aside::-webkit-scrollbar {
  display: none;
}

// .dropdown-item:hover {
//   color: #000000;
//   background-color: #770000;
// }
// .dropdown-menu:hover {
//   color: #000000;
  
// }
// .dropdown-menu {
//   background-color: #770000;
//   color: #fff;
  
// }
</style>
